package com.ocom.srvpaccess;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.PropertyNamingStrategy;
import com.alibaba.fastjson.serializer.SerializeConfig;
import lombok.Data;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;

import java.io.UnsupportedEncodingException;
import java.util.Base64;
import java.util.HashMap;
import java.util.Map;

@SpringBootTest
public class YkmRequest {

	/**
	 * {"version":"1.0","service":"yct.skinfo.device.logon.return","seq":"14356141511348111293414813584116","retcode":"000000","jsondata":"eyJ0b2tlbiI6IjIzMDI4OTcwMjMxNzIxNTMyMjE3NDE4MjQxNTAxMzM2IiwiZXhwaXJlZGF0ZSI6IjIwOTkxMjMxMjM1OTU5In0=","sign":"5390A9262B8CAE20"}
	 * @throws UnsupportedEncodingException
	 */

	@Test
	public void tes() throws UnsupportedEncodingException {
//		long l = new Date().getTime() / 1000;
		String l = "1649207495";
		Map<String,Object> map=new HashMap<>();
		map.put("version","1.0");
		map.put("service","yct.skinfo.device.logon");
		map.put("token","null");
		map.put("timestamp", l );
		map.put("type","100");
		map.put("sender","XINAOKANG");
		map.put("seq","00000000000000000000000000000001");

		User user = new User();
		user.setDeviceid("301F9A843B96");
		SerializeConfig config = new SerializeConfig();
		config.propertyNamingStrategy = PropertyNamingStrategy.SnakeCase;
		String json = JSON.toJSONString(user, config);
		System.out.println(json);

		String base64EncStr= new String (Base64.getEncoder().encode(json.getBytes())); //第二种 转Base64

		map.put("jsondata", base64EncStr );

		String signStr="version=1.0&service=yct.skinfo.device.logon&token=null&timestamp="+ l +"&type=100&sender=XINAOKANG&seq="+map.get("seq")+"&jsondata="+base64EncStr+"&sign_key=16357019006243204251202396312980";

//		String md5= Md5Utils.getMD5(signStr.getBytes(StandardCharsets.UTF_8)).toUpperCase().substring(8,24);
//		System.out.println(signStr);
//		System.out.println(md5);
//		map.put("sign",md5);
//		String s = RequestUtil.doPost("https://wxtest.gzyct.com:6810/yct/skinfo/post", new Gson().toJson(map));
//		System.out.println(s);

	}


	@Data
	public class User{
		String deviceid;
		String term="";
		String password="";
	}
}
